#include "TestScreen.h"

Assets* g_pAssets = NULL;

TestScreen::TestScreen() : gfxStats(NULL), m_roomTest(NULL), m_numOfObjects(0), m_camera(NULL)
{
	m_camera			= new cCamera2D(D3DXVECTOR3(320.0f, 320.0f, -800.0f), D3DXVECTOR3(320.0f, 320.0f, 0.0f), D3DXVECTOR3(0.0f, 1.0f, 0.0f));
	m_roomTest			= new Room(1, 0);
	m_numOfObjects		= 100;
	gfxStats			= new GfxStats();
	gfxStats->addVertices(m_numOfObjects*4);
	gfxStats->addTriangles(m_numOfObjects*2);
	m_camera->BuildCameraView();
	m_camera->BuildCameraProjection();
}

TestScreen::~TestScreen() 
{
	delete m_camera;
	delete m_roomTest;
	delete gfxStats;
}

void TestScreen::renderScreen() 
{
	//Starts the rendering process of a scene using	ID3DXSprite9 object
	g_pGraphics->beginSpriteRender(D3DXSPRITE_OBJECTSPACE | D3DXSPRITE_DONOTMODIFY_RENDERSTATE);

	m_roomTest->renderRoom();

	//g_pD3DDevice->SetTransform(D3DTS_VIEW, &m_camera->m_view);
	//g_pD3DDevice->SetTransform(D3DTS_PROJECTION, &m_camera->m_projection);
	g_pD3DDevice->SetTransform(D3DTS_WORLD,&(m_camera->m_view * m_camera->m_projection));

	g_pGraphics->flushSprites();
	
	//Stops the rendering process for the ID3DXSprite object
	g_pGraphics->endSpriteRender();

	//Draws the frame rate to the screen
	gfxStats->displayStats();
}

void TestScreen::updateScreen(float dt) 
{
	gfxStats->update(dt);
}

void TestScreen::onResetDevice()
{
	//gfxStats->onResetDevice();
	g_pGraphics->onResetDevice();
}

void TestScreen::onLostDevice()
{
	//gfxStats->onLostDevice();
	g_pGraphics->onLostDevice();
}